class Solution {
    public int takeAttendance(int[] records) {
        int left = 0, right = records.length - 1;
        // 二分查找第一个records[i]!= i的位置
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (records[mid] == mid) {
                left = mid + 1; // 0..mid都到勤，缺失值在右半段
            } else {
                right = mid; // 缺失值在左半段或就是 mid
            }
        }
        // 如果 records[left] == left，说明 0..left 都到勤，缺失值是 left+1
        return (left == records[left]) ? left + 1 : left;
    }
}